home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14660 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  62 lines

  1. Path: holly.ACNS.ColoState.EDU!not-for-mail
  2. From: corbyh@holly.ACNS.ColoState.EDU (Corby S. Hudnall)
  3. Newsgroups: comp.lang.c++
  4. Subject: Proper use of friend keyword
  5. Date: 31 Mar 1996 16:17:40 -0700
  6. Organization: Colorado State University, Fort Collins, CO  80523
  7. Message-ID: <4jn3qk$3tl6@holly.ACNS.ColoState.EDU>
  8. NNTP-Posting-Host: holly.acns.colostate.edu
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. Hey all, I have a question about how to use the friend keyword.  Consider
  12. the following example:
  13.  
  14. class.h---------
  15. class ABC
  16. {
  17.     int AValue;
  18.     int GetAValue() { return (AValue); }
  19. public:
  20.     ABC() { AValue=5; }
  21.     ~ABC(){ }
  22. };
  23.  
  24. class XYZ
  25. {
  26. public:
  27.     XYZ() { }
  28.     ~XYZ() { }
  29.     friend int ABC::GetAValue();
  30. };
  31.  
  32. prog.C--------------------
  33. #include <iostream.h>
  34. #include "class.h"
  35.  
  36. void main()
  37. {
  38.   ABC abc;
  39.   XYZ xyz;
  40.  
  41.   cout << xyz.GetAValue() << endl
  42. }
  43.  
  44.  
  45. when I try to compile this, I get the message "no member funciton 
  46. 'XYZ::GetAValue()' defined."  What do I need to do in order to 
  47. make this work.  Thanks for any and all suggestions.
  48.  
  49. // ------------ BEGIN SIGNATURE ---------------
  50. #include <iostream.h>
  51. void main(void)
  52. {
  53.   cout << "\aName:\tCorby S. Hudnall\n"
  54.        << "School:\tColorado State University\n"
  55.        << "\tDepartement of Computer Science\n"
  56.        << "EMail:\thudnall@CS.ColoState.EDU\n"
  57.        << "URL:\thttp://WWW.CS.ColoState.EDU/~hudnall\n";
  58. }
  59. // ------------ END SIGNATURE -----------------
  60.  
  61.  
  62.